package huang.com.android.recycleview;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class RecycleViewActivity extends AppCompatActivity {

    private List<imageText> imagetextList = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycle_view);

        init();

        android.support.v7.widget.RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycle_view);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        //横向列表
        //layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        //网格布局的列表
        //GridLayoutManager layoutManager=new GridLayoutManager ( this,3 );
        //分割线设置

        recyclerView.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));

        recyclerView.setLayoutManager(layoutManager);
        RecycleViewAdapter adapter = new RecycleViewAdapter(imagetextList);
        recyclerView.setAdapter(adapter);
    }

    private void init() {
        for(int i=0;i<5;i++) {
            imageText a = new imageText ( "aaa", R.mipmap.ic_launcher );
            imagetextList.add ( a );
            imageText b = new imageText ( "bbb", R.mipmap.ic_launcher );
            imagetextList.add ( b );
            imageText c = new imageText ( "ccc", R.mipmap.ic_launcher );
            imagetextList.add ( c );
            imageText d = new imageText ( "ddd", R.mipmap.ic_launcher );
            imagetextList.add ( d );
            imageText e = new imageText ( "eee", R.mipmap.ic_launcher );
            imagetextList.add ( e );
            imageText f = new imageText ( "fff", R.mipmap.ic_launcher );
            imagetextList.add ( f );
        }
    }
}
